;; EX-05.scm - Mapping an Argument to a Control Bus

;; Define a synth to play a sine wave with a frequency parameter.

(synthdef-send
 (synthdef
  "sine"
  ((out 0) (freq 440) (ampl 0.1))
  (Out.ar out (SinOsc.ar freq 0 ampl))))

;;  Define a synth to write to a control bus.

(synthdef-send
 (synthdef
  "line"
  ((bus 0) (start 1000) (end 500) (time 1))
  (ReplaceOut.kr bus (Line.kr start end time))))

;; Play a 900 Hz sine wave.

(-> "/s_new" "sine" 1000 1 1 "freq" 900)

;; Put a frequency value on the control bus.

(-> "/c_set" 10 1000)

;; Map the node's 'freq' argument to read from control bus #10.

(-> "/n_map" 1000 "freq" 10)

;; Change the value on the control bus.

(-> "/c_set" 10 1200)

;; Start a control process that writes to control bus #10.

(-> "/s_new" "line" 1001 1 1 "bus" 10)

;; Free the control node.

(-> "/n_free" 1001)

;; Unmap the frequency control.

(-> "/n_map" 1000 "freq" -1)

;; The n_set command is disabled while an n_map is in effect.

(-> "/n_set" 1000 "freq" 220 "ampl" 0.4)

;; Free signal node.

(-> "/n_free" 1000)
